package cn.com.b2office.struts2.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.com.b2office.domain.Cart;
import cn.com.b2office.domain.User;

import com.opensymphony.xwork2.ActionSupport;

public class SaveOrderCustomAction extends ActionSupport implements
		SessionAware {

	private static final long serialVersionUID = -5855397467342739081L;

	private Map session = null;

	private String addressId = null;

	private int deliveryMode = 0;

	private int payMode = 0;

	private int split = 1;

	private String resultURL = null;

	public void validate() {
		if (addressId == null || addressId.trim().equals(""))
			this.addFieldError("addressId", "请选择配送地址!");
	}

	public String execute() throws Exception {
		Cart cart = (Cart) session.get("cart");
		User user = (User) session.get("user");
		if (user == null || cart == null)
			return "login";

		if (addressId != null && !addressId.trim().equals("")) {
			cart.setDeliveryMode(deliveryMode);
			cart.setPayMode(payMode);
			cart.setSplit(split);
			cart.setAddressId(addressId);
			if(resultURL!=null&&!resultURL.trim().equals(""))
				return "resultURL";
			return SUCCESS;
		} else {
			this.addActionError("请选择配送地址.");
			return "input";
		}
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public void setAddressId(String addressId) {
		this.addressId = addressId;
	}

	public void setDeliveryMode(int deliveryMode) {
		this.deliveryMode = deliveryMode;
	}

	public void setPayMode(int payMode) {
		this.payMode = payMode;
	}

	public void setSplit(int split) {
		this.split = split;
	}

	public String getResultURL() {
		return resultURL;
	}

	public void setResultURL(String resultURL) {
		this.resultURL = resultURL;
	}

}
